<?php

require_once 'const/DBConst.php';

class Application_Model_TypeMapper {

    public static function insert($type) {
        $db = Zend_Registry::get("database");
        $date = array(
            C_NAME => $type->getName()
        );
        $db->insert(T_PRODUCT_TYPE, $date);
        return $db->lastInsertId();
    }

    public static function fetch($id) {
        $db = Zend_Registry::get("database");
        $result = $db->fetchRow("SELECT * FROM " . T_PRODUCT_TYPE . " WHERE ID=" . $id);
        return $result;
    }

    public static function update($type) {
        $db = Zend_Registry::get("database");
        $date = array(
            C_NAME => $type->getName()
        );
        $db->update(T_PRODUCT_TYPE, $date, "ID=" . $type->getId());
    }

    public static function delete($id) {
        $db = Zend_Registry::get("database");
        $db->delete(T_PRODUCT_TYPE, 'ID=' . $id);
    }

    public static function fetchAll() {
        $db = Zend_Registry::get("database");
        $result = $db->fetchAll("SELECT * FROM " . T_PRODUCT_TYPE);
        return $result;
    }

}

